#ifndef __OACTION_INSTANT_H__
#define __OACTION_INSTANT_H__

	/** @brief Calls a 'callback' function. */
	class oDLL oCallFunc : public CCActionInstant
	{
	public:
		oCallFunc():m_pSelectorTarget(nullptr), m_pCallFunc(nullptr){}
		/** Use a weak reference of target. */
		static oCallFunc* actionWithTarget(CCObject* pSelectorTarget, SEL_CallFunc selector);
		/** Initializes the action with the callback 
		typedef void (CCObject::*SEL_CallFunc)();
		*/
		virtual bool initWithTarget(CCObject* pSelectorTarget);
		/** Executes the callback */
		virtual void execute();
		virtual void startWithTarget(CCNode *pTarget);
		/** Super methods, not implement. */
		CCObject* copyWithZone(CCZone *pZone);

		inline CCObject* getTargetCallback()
		{
			return m_pSelectorTarget;
		}

		inline void setTargetCallback(CCObject* pSel)
		{
			if (pSel != m_pSelectorTarget)
			{
				m_pSelectorTarget = pSel;
			}
		}

	protected:
		/** Target that will be called */
		CCObject*   m_pSelectorTarget;

		union
		{
			SEL_CallFunc	m_pCallFunc;
			SEL_CallFuncN	m_pCallFuncN;
			SEL_CallFuncND	m_pCallFuncND;
            SEL_CallFuncO   m_pCallFuncO;
		};
	};

	/** 
	@brief Calls a 'callback' with the node as the first argument
	N means Node
	*/
	class oDLL oCallFuncN : public oCallFunc
	{
	public:
		oCallFuncN(){}
		virtual ~oCallFuncN(){}
		/** creates the action with the callback 
		typedef void (CCObject::*SEL_CallFuncN)(CCNode*);
		Use a weak reference of target.
		*/
		static oCallFuncN * actionWithTarget(CCObject* pSelectorTarget, SEL_CallFuncN selector);
		/** initializes the action with the callback 
		typedef void (CCObject::*SEL_CallFuncN)(CCNode*);
		*/
		virtual bool initWithTarget(CCObject* pSelectorTarget, SEL_CallFuncN selector);
		/** Super methods, not implement. */
		virtual CCObject* copyWithZone(CCZone *pZone);
		virtual void execute();
	};

#endif
